package app

import (
	"cloud-navigation/app/common/response"
	"cloud-navigation/app/models"
	"cloud-navigation/global"

	"github.com/gin-gonic/gin"
)

// 获取导航分类
func Assort(c *gin.Context) {
	var ass []models.Assort
	if err := global.App.DB.Order("sort").Find(&ass).Error; err != nil {
		response.BusinessFail(c, "查询失败")
		return
	}
	response.Success(c, ass)
}

// 获取导航列表
func Navigation(c *gin.Context) {
	var (
		// navi []models.Navigation
		ass []models.Assort
	)
	// err := global.App.DB.Table("navigations").Preload("Assort").Order("created_at, sort").Find(&navi).Error
	// if err != nil {
	// 	response.BusinessFail(c, "查询失败")
	// 	return
	// }
	if err := global.App.DB.Table("assorts").Preload("Navigation").Order("sort").Find(&ass).Error; err != nil {
		response.BusinessFail(c, "查询失败")
		return
	}
	response.Success(c, ass)
	// response.Success(c, navi)
}
